#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const inquirer = require('inquirer');
const ejs = require('ejs');

inquirer.prompt([
  {
    type: 'input',
    name: 'name',
    message: 'project name'
  }
]).then(answer => {
  // console.log(answer);
  const tmpDir = path.join(__dirname, 'templates');  // 模板路径
  const aimDir = process.cwd();   // 当前命令行的路径

  fs.readdir(tmpDir, (err, res) => {
    if (err) throw err;

    res.forEach(file => {
      ejs.renderFile(path.join(tmpDir, file), answer, (err, result) => {
        if (err) throw err;
        fs.writeFileSync(path.join(aimDir, file), result);
      })
    })
  })
})